package com.dong.pointviewpager.utils

import android.content.Context
import android.graphics.Point
import android.view.WindowManager

/**
 * @description:屏幕尺寸适配
 * @author dong
 * @date 2021/12/16 9:08
 */
object DensityUtils {

    private const val PAGE_SCREEN_WIDTH = 360

    fun dp2px(context: Context, value: Float): Float{
        return value * screenWidth(context)/ PAGE_SCREEN_WIDTH
    }

    private fun screenWidth(context: Context): Int {
        val windowManager = context.applicationContext.getSystemService(Context.WINDOW_SERVICE) as WindowManager
        val screenPoint = Point()
        windowManager.defaultDisplay.getSize(screenPoint)
        return screenPoint.x
    }
}